package com.irs.irsforum.exception.impl;

import com.irs.irsforum.exception.ExceptionType;
import com.irs.irsforum.exception.IIrsForumException;
import org.apache.log4j.Level;
/**
 * @author Liyihui
 * @Date: 2020/3/22
 * @Time: 3:09
 */
public class IrsForumExceptionImpl extends RuntimeException  implements IIrsForumException {

    protected ExceptionType exceptionType;

    public IrsForumExceptionImpl(String message, ExceptionType exceptionType) {
        super(composeMessage(exceptionType, message));
        this.exceptionType = exceptionType;
    }
    public IrsForumExceptionImpl(Throwable cause, ExceptionType exceptionType) {
        this("", cause, exceptionType);
    }

    public IrsForumExceptionImpl(String message, Throwable cause, ExceptionType exceptionType) {
        super(composeMessage(exceptionType, message), cause);
        this.exceptionType = exceptionType;
    }

    static String composeMessage(ExceptionType exceptionType, String message) {
        return "Message[" + exceptionType.getName() + "]: " + message;
    }

    @Override
    public ExceptionType getExceptionType() {
        return exceptionType;
    }
}
